package com.cd.common.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanConfiguration {


    @Value("${lqq.redis.sentinel.master}")
    private String master;

    @Value("${lqq.redis.sentinel.address}")
    private String address;

    @Value("${spring.redis.database}")
    private Integer dataBase;

    @Value("${spring.redis.password}")
    private String password;

    @Bean("redissonClient")
    public RedissonClient redisson() {
//        集群模式的
//        Config redisConfig=new Config();
//        redisConfig.useSentinelServers()
//                //.setScanInterval(2000) // cluster state scan interval in milliseconds
//                //.addSentinelAddress(address.split(","))
//                //.setCheckSentinelsList(false)
//                //.setMasterName(master)
//                .setPassword(password)
//                .setDatabase(dataBase);
//        RedissonClient redissonClient = Redisson.create(redisConfig);

        //单机模式的
        Config redisConfig=new Config();
        redisConfig
                .useSingleServer()
                .setAddress(address)//(ADDRESS_PREFIX + host + ":" + port)
                .setPassword(password)
                .setDatabase(dataBase);
        RedissonClient redissonClient = Redisson.create(redisConfig);
        return redissonClient;
    }
}
